<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap-select.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/bootstrap3/bootstrap.min.js" type="text/javascript"></script>
<script src="/res/third/bootstrap3/bootstrap-select.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>

<script type="text/javascript">

	function sosuo(){
		var lpath =location.pathname;
		var pageNo = $("#pageNo").val();
		$("#soform").attr("action",lpath+"?pageNo="+pageNo);
		$("#soform").submit();
	}
	function edit(userid){
		var editdialog =art.dialog({title:"编辑"});
		$.ajax({
		    url: '/user/v_edit.do',
		    data:{userid:userid},
		    success: function (data) {
		    	editdialog.content(data);
		    }
		});
	}
	
	//删除（软删除）
	function del(userid){//弹出警告框判断是否删除
		if(confirm('是否确认删除')){
				$.ajax({
					url : '/user/ajax_del.do',
					type : 'get',
					dataType : 'json',
					data : {
						id : userid
					},
					beforeSend:function(){
			            art.dialog.tips("删除中...");
			        },
					success : function(data){
						if(data.success){
							location.reload();
						}else{
							error_msg(data.msg , function(){location.reload();});
						}
					}
				});
		}
	}
	
	//禁用启用
	function disable(userid){//弹出警告框判断是否删除
				$.ajax({
					url : '/user/ajax_disable.do',
					type : 'get',
					dataType : 'json',
					data : {
						id : userid
					},
					beforeSend:function(){
			            art.dialog.tips("处理中...");
			        },
					success : function(data){
						if(data.success){
							location.reload();
						}else{
							error_msg(data.msg , function(){location.reload();});
						}
					}
				});

	}
	
	
	/*重置密码*/
	function resetpwd(userid,username){
		$("#username").text(username);
		$("#userid").val(userid);
		 resetdialog =art.dialog({title:"密码重置",content:document.getElementById('resetpwdmodel')});
	}
	
	function submitreset(){
		art.dialog.get({
			url: '/user/o_resetpwd.do',
			data:$("#resetform").serialize(),
			success:function(data){
				resetdialog.close();
				art.dialog.tips(data.msg);
			}
		});
	}

</script>
</head>

<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading">
		<form  id="soform" method="post" >
		
		<table >
			<tr>
				<td class="w80 ">
					<label  for="so_userrole" class="center-block"  >企业身份:</label>
				</td>
				<td class="w120 ">
					<select class="form-control"  id="so_userrole" name="so_userrole"  >
						<option [#if !so_userrole?? || so_userrole=="0"] selected="selected"  [/#if]  value="0"  >全部</option>
						<option [#if so_userrole?? && so_userrole=="1" ] selected="selected"  [/#if]  value="1"  >采购商</option>
						<option [#if so_userrole?? && so_userrole=="2" ] selected="selected"  [/#if]  value="2"  >供应商</option>
						<option [#if so_userrole?? && so_userrole=="3" ] selected="selected"  [/#if]  value="3"  >采购商,供应商</option>
					</select>
				</td>
				<td>
					<div class="input-group">
						<input type="text" class="form-control"  name="so_userinfo"  value="${so_userinfo!}" placeholder="手机,邮箱,姓名,企业名称">
						<span class="input-group-btn">
							<button class="btn btn-default" type="button" onclick="sosuo()">搜索</button>
						</span>
					</div>
				</td>
			</tr>
		</table>
		</form>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
			<thead>
				<tr>
					<th>#序号</th>
					<th>手机</th>
					<th>邮箱</th>
					<th width="200px">所属公司</th>
					<th width="200px">上级公司</th>
					<th>角色</th>
					<th>真实姓名</th>
					<th>状态</th>
					<th>采购商</th>
					<th>供应商</th>
					<th>操作</th>
				</tr>
			</thead>
			[#list pagination.list  as usercompany]
			<tr>
				<td>${pagination.pageSize * (pagination.pageNo-1) + usercompany_index+1!}</td>
				<td>${usercompany.user.mobile!}[#if usercompany.user.userEmail?? ]${usercompany.user.userEmail.id}[/#if]</td>
				<td>${usercompany.user.email!}</td>
				<td>[#if usercompany.company??]${usercompany.company[0].companyName!}[#if usercompany.company[0].parentId??][#else][/#if][/#if]</td>
				<td>[#if usercompany.company??][#if usercompany.company[1]??][#if usercompany.company[1].parentId??]【上级公司】[#else]【总公司】[/#if]${usercompany.company[1].companyName!}[/#if]</br>[#if usercompany.company[2]??]【总公司】${usercompany.company[2].companyName!}[/#if][/#if]</td>
				<td>[#if usercompany.user.rolenames??]${usercompany.user.rolenames!}[/#if]</td>
				<td>${usercompany.user.realName!}</td>
				<td>[#if usercompany.user.state?? &&usercompany.user.state==0]禁用[#else]启用[/#if]</td>
				<td>[#if usercompany.company?? && usercompany.company[0].ispurchaser==1 ]<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>[#else]否[/#if]</td>
				<td>[#if usercompany.company?? && usercompany.company[0].isprovider==1 ]<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>[#else]否[/#if]</td>
				<td>
					<button class="btn btn-info btn-xs"  onclick="edit(${usercompany.user.id})" >编辑</button>
					<button class="btn btn-info btn-xs"  onclick="resetpwd(${usercompany.user.id},'[#if usercompany.user.mobile?? && usercompany.user.mobile?length gt 7]${usercompany.user.mobile!}[#else]${usercompany.user.email!}[/#if]')" >重置密码</button>
					 <button class="btn btn-info btn-xs"  onclick="del(${usercompany.user.id})" >删除</button>
					[#if usercompany.user.state?? &&usercompany.user.state==0]
				    <button class="btn btn-primary btn-xs"  onclick="disable(${usercompany.user.id})" style="margin-left:0">启用</button>  
				    [#else]
				    <button class="btn btn-danger btn-xs"  onclick="disable(${usercompany.user.id})">禁用</button>  
				    [/#if]
                    <button class="btn btn-success btn-xs"  onclick="history(${usercompany.user.id})">历史操作</button>  
				</td>
			</tr>
			[/#list]
		</table>

		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>
	
	
	<!--  模板  重置密码  -->
	<div   id="resetpwdmodel" style="display: none;">
		<div>
			<form id="resetform"  >
				<input  id="userid" type="hidden" value="" name="userid" >
				<table class="table table-hover table-bordered" >
					<tr >
						<th  >用户名</th>
						<td  id="username" ></td>
					</tr>	
					<tr>
						<th >
							新密码
						</th>
						<td>
							<input  class="form-control"  name="newpassword"  placeholder="默认:123456" >
						</td>
					</tr>
				</table>
				
				<div class="center-block">
					<button type="button" class="btn btn-success" onclick="submitreset()">提交</button>
				</div>
			</form>
		</div>
	</div>
</body>
</html>